package com.yhg.context.service.impl;

import com.yhg.context.entity.BlType;
import com.yhg.context.mapper.BlTypeMapper;
import com.yhg.context.service.BlTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 帖子类型表 服务实现类
 * </p>
 *
 * @author 白小白
 * @since 2021-02-01
 */
@Service
public class BlTypeServiceImpl extends ServiceImpl<BlTypeMapper, BlType> implements BlTypeService {

    @Autowired
    BlTypeMapper typeMapper;

    @Override
    public List<BlType> listAll() {
        List<BlType> typeList = typeMapper.listAll();
        return typeList;
    }

    @Override
    public Map<String, Object> getTypeMap() {
        //查询所有的分类
        List<BlType> types = baseMapper.listAll();
        //封装,一行一行来
        Map<String, Object> collect = types.stream().collect(Collectors.toMap(key -> key.getTypeId().toString(), value -> value.getTypeName()));//key，value可以自己取，代表的就是一个对象
        return collect;
    }
}
